import StoreBase, { IStoreBaseMeta } from '../../common/stores/StoreBase';
import {observable,autorun,action, computed} from 'mobx';
import { observablePromise,ObservableTempState } from 'legions/store-utils';
import { StoreModules } from 'legions/store';
import {MicroAppStateActions} from 'legions-micro-service/types/interfaces'
import { UserInfoEntity } from '../models/userInfoEntity';
interface IContext{
/*  UserInfoApp:UserInfoStore, */
}
interface IGlobalState{
    user?: UserInfoEntity;
}
interface IIGlobalStateEvent{
    name: string;
    scope: string;
}
@StoreModules
export default class GlobalStateStore extends StoreBase<IContext>{
    static meta :IStoreBaseMeta={
        ...StoreBase.meta,
        /* eventScopes: [User], */
        contextTypes:{
        },
    }
    /** 用户信息 */
    userInfo: UserInfoEntity = null;
    onGlobalStateChange: (callback:(value:IGlobalState,prev:IGlobalState,event:IIGlobalStateEvent)=>void,options:Parameters<MicroAppStateActions['onGlobalStateChange']>[1])=>void = null;
    setGlobalState: (state: IGlobalState,event: IIGlobalStateEvent)=>void =null;
    constructor(context:IContext){
        super(context);
    }
    syncUpdateGlobalState(props: {
        onGlobalStateChange: MicroAppStateActions['onGlobalStateChange'],
        setGlobalState: MicroAppStateActions['setGlobalState'] 

    }) {
        if (!this.onGlobalStateChange) {
            this.onGlobalStateChange = (callback,options) => {
                props.onGlobalStateChange(callback,options);
            };
        }
        if (!this.setGlobalState) {
            this.setGlobalState = (state,event) => {
                props.setGlobalState(state,event)
            };
        }
    }
}
